package com.example.tao.mybroadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class MyBroadcastReceiver extends BroadcastReceiver {

    private IOnChangeText onChangeText;

    public void setOnChangeText(IOnChangeText onChangeText) {
        this.onChangeText = onChangeText;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")){
            ConnectivityManager connectionManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectionManager.getActiveNetworkInfo();
            if (networkInfo != null && networkInfo.isAvailable()) {
                onChangeText.setText("network is available");
            } else {
                onChangeText.setText("network is unavailable");
            }
        }else{
            onChangeText.setTime();
        }
    }
}
